<?php
/**
 * 
 * @author jason
 *
 */
class UserApi extends Api{

	/**
	 * 按用户UID或昵称返回用户资料，同时也将返回用户的最新发布的微博
	 * 
	 */
	function show(){
		//$this->user_id = empty($this->user_id) ? $this->mid : $this->user_id;
		//用户基本信息
		$nodata['status'] = 0;
		if(empty($this->user_id) && empty($this->user_name)){
			return $nodata;
		}
		if(empty($this->user_id)){
			$data = model('User')->getUserInfoByName($this->user_name);	
			$this->user_id = $data['uid'];
		}else{
			$data = model('User')->getUserInfo($this->user_id);	
		}
		if(empty($data)){
			return $nodata;
		}
		$data['sex'] = $data['sex'] ==1 ? '男':'女';
		
		$data['profile'] = model('UserProfile')->getUserProfileForApi($this->user_id);

		$profileHash = model('UserProfile')->getUserProfileSetting();
		$data['profile']['email'] = array('name'=>'邮箱','value'=>$data['email']);
		foreach(UserProfileModel::$sysProfile as $k){
			if(!isset($data['profile'][$k])){
				$data['profile'][$k] = array('name'=>$profileHash[$k]['field_name'],'value'=>'');
			}
		}

		//用户统计信息
		$defaultCount =  array('following_count'=>0,'follower_count'=>0,'feed_count'=>0,'favorite_count'=>0,'unread_atme'=>0,'weibo_count'=>0);

		$count   = model('UserData')->getUserData($this->user_id);
		if(empty($count)){
			$count = array();	
		}
		$data['count_info'] = array_merge($defaultCount,$count);
		
		//用户标签
		$data['user_tag'] = model('Tag')->setAppName('User')->setAppTable('user')->getAppTags($this->user_id);
		$data['user_tag'] = empty($data['user_tag']) ? '' : implode('、',$data['user_tag']);
		//关注情况
		$followState  = model('Follow')->getFollowState($this->user_id,$this->user_id); 
		$data['follow_state'] = $followState;
		
		//最后一条微博
		$lastFeed = model('Feed')->getLastFeed($this->user_id);
		$data['last_feed'] = $lastFeed;

		// 判断用户是否被登录用户收藏通讯录
		$data['isMyContact'] = 0;
		if($this->user_id != $this->user_id) {
			$cmap['uid'] = $this->user_id;
			$cmap['contact_uid'] = $this->user_id;
			$myCount = D('Contact', 'contact')->where($cmap)->count();
			if($myCount == 1) {
				$data['isMyContact'] = 1;
			}
		}

		$seccuss['status'] = 1;
		return $seccuss+$data;
	}
		
	/**
	 * 上传头像 API
	 * 传入的头像变量 $_FILES['Filedata']
	 */
	function upload_face(){
		$dAvatar = model('Avatar');
		$dAvatar->init($this->user_id); // 初始化Model用户id
		$res = $dAvatar->upload(true);
		//Log::write(var_export($res,true));
		if($res['status'] == 1){
			$data['picurl'] = $res['data']['picurl'];
			$data['picwidth'] = $res['data']['picwidth'];
			$scaling = 5;
			$data['w'] = $res['data']['picwidth'] * $scaling;
			$data['h'] = $res['data']['picheight'] * $scaling;
			$data['x1'] = $data['y1'] = 0;
			$data['x2'] = $data['w'];
			$data['y2'] = $data['h'];
			$r = $dAvatar->dosave($data);
		}else{
			return '0';
		}
	}

	/**
	 *	关注一个用户
	 */
	public function follow_create(){
		$f['status'] = 0;
		$s['status'] = 1;
		$follow_user_id = $_GET['follow_user_id'];
		if(empty($this->user_id) || empty($follow_user_id)){
			return $f;
		}

		$r = model('Follow')->doFollow($this->user_id,$follow_user_id);
		if(!$r){
			return $s + model('Follow')->getFollowState($this->user_id,$follow_user_id);
			//return 0;
		}
		return $s + $r;
	}

	/**
	 * 取消关注
	 */
	public function follow_destroy(){
		$f['status'] = 0;
		$s['status'] = 1;
		$follow_user_id = $_GET['follow_user_id'];
		if(empty($this->user_id) || empty($follow_user_id)){
			return $f;
		}
		
		$r = model('Follow')->unFollow($this->user_id,$follow_user_id);
		if(!$r){
			return $s + model('Follow')->getFollowState($this->user_id,$follow_user_id);
		}
		return $s + $r;
	}

	public function addStatus($data){
		$f['status'] = 0;
		$s['status'] = 1;
		$tdata['data'] = $data;
		if($tdata['data'] == null || $tdata['data'] == false || $tdata['data'] == [])
			return $f + $tdata;
		else
			return $s + $tdata;
	}
	/**
	 * 用户粉丝列表
	 */
	public function user_followers(){		
		$this->user_id = empty($this->user_id) ? $this->user_id : $this->user_id;
		// 清空新粉丝提醒数字
		if($this->user_id == $this->user_id){
			$udata = model('UserData')->getUserData($this->user_id);
			$udata['new_folower_count'] > 0 && model('UserData')->setKeyValue($this->user_id,'new_folower_count',0);	
		}
		
		//return model('Follow')->getFollowerListForApi($this->user_id,$this->user_id,$this->since_id,$this->max_id,$this->count,$this->page);
		
		//给数组加key
		return $this->addStatus(model('Follow')->getFollowerListForApi($this->user_id,$this->user_id,$this->since_id,$this->max_id,$this->count,$this->page));
	}

	/**
	 * 获取用户关注的人列表
 	 */
	public function user_following(){
		$this->user_id = empty($this->user_id) ? $this->user_id : $this->user_id;
		//return model('Follow')->getFollowingListForApi($this->user_id,$this->user_id,$this->since_id,$this->max_id,$this->count,$this->page);
	
		//给数组加key
		return $this->addStatus(model('Follow')->getFollowingListForApi($this->user_id,$this->user_id,$this->since_id,$this->max_id,$this->count,$this->page));
		
	}

	/**
	 * 获取用户的朋友列表
	 * 
	 */
	public function user_friends(){
		$this->user_id = empty($this->user_id) ? $this->user_id : $this->user_id;
		//return model('Follow')->getFriendsForApi($this->user_id, $this->user_id, $this->since_id, $this->max_id, $this->count, $this->page);
	
		//给数组加key
		return $this->addStatus(model('Follow')->getFriendsForApi($this->user_id, $this->user_id, $this->since_id, $this->max_id, $this->count, $this->page));
		
	}

	// 按名字搜索用户
	public function wap_search_user(){
		$key = t($this->data['key']);
		$map['uname'] = array('LIKE',$key);
		$userlist = M('user')->where($map)->findAll();
		if($userlist == null)
			$userlist = [];
		return $this->addStatus($userlist);
	}

	/**
	 * 获取用户相关信息
	 * @param array $uids 用户ID数组
	 * @return array 用户相关数组
	 */
	public function getUserInfos($uids, $data, $type = 'basic')
	{
		// 获取用户基本信息
		$userInfos = model('User')->getUserInfoByUids($uids);
		$userDataInfo = model('UserData')->getUserKeyDataByUids('follower_count',$uids);

		if($type=='all'){
		// 获取其他用户统计数据
			// 获取关注信息
			$followStatusInfo = model('Follow')->getFollowStateByFids($this->user_id, $uids);
			// 获取用户组信息
			$userGroupInfo = model('UserGroupLink')->getUserGroupData($uids);
		}

		// 组装数据
		foreach($data as &$value) {
			$value = array_merge($value, $userInfos[$value['uid']]);
			$value['user_data'] = $userDataInfo[$value['uid']];
			if($type=='all'){	
				$value['follow_state'] = $followStatusInfo[$value['uid']];
				$value['user_group'] = $userGroupInfo[$value['uid']];
			}
		}
	
		return $data;
	}
	// 按标签搜索用户
	public function search_by_tag()
	{
		$limit = 20;
		$this->data['limit'] && $limit = intval( $this->data['limit'] );
		$tagid = intval ( $this->data['tagid'] );
		if ( !$tagid ){
			return $this->addStatus([]);
		}
		$data = model('UserCategory')->getUidsByCid($tagid, null ,$limit);
		$data['data'] = $this->getUserInfos ( getSubByKey( $data['data'] , 'uid' ) , $data['data'],'basic');
		return $this->addStatus($data['data'] ? $data : []);
	}

	// 按地区搜索用户
	public function search_by_area($value='')
	{
		$_REQUEST['p'] = $_REQUEST['page'] = $this->page;
		$limit = 20;
		$this->data['limit'] && $limit = intval( $this->data['limit'] );
		$areaid = intval ( $this->data['areaid'] );
		if ( !$areaid && $this->data['areaname']){
			$amap['title'] = t( $this->data['areaname'] );
			$areaid = D('area')->where($amap)->getField('area_id');
		}
		if ( !$areaid ){
			return $this->addStatus([]);
		}
		
		$pid1 = model('Area')->where('area_id='.$areaid)->getField('pid');
		$level = 1;
		if($pid1 != 0){
			$level = $level +1;
			$pid2 = model('Area')->where('area_id='.$pid1)->getField('pid');
			if($pid2 != 0){
				$level = $level +1;
			}
		}
		switch ($level) {
			case 1:
				$map['province'] = $areaid;
				break;
			case 2:
				$map['city'] = $areaid;
				break;
			case 3:
				$map['area'] = $areaid;
				break;
		}
		
		$map['is_del'] = 0;
		$map['is_active'] = 1;
		$map['is_audit'] = 1;
		$map['is_init'] = 1;
		
		$data = D('user')->where($map)->field('uid')->order("uid desc")->findPage($limit);
		$data['data'] = $this->getUserInfos ( getSubByKey( $data['data'] , 'uid' ) , $data['data'],'basic');

		return $this->addStatus($data['data'] ? $data : []);
	}

	// 按认证分类搜索用户
	public function search_by_verify_category($value='')
	{
		$limit = 20;
		$this->data['limit'] && $limit = intval( $this->data['limit'] );
		$verifyid = intval ( $this->data['verifyid'] );
		if ( !$verifyid && $this->data['verifyname']){
			$amap['title'] = t( $this->data['verifyname'] );
			$verifyid = D('user_verify_category')->where($amap)->getField('user_verified_category_id');
		}
		if ( !$verifyid ){
			return $this->addStatus([]);
		}
		$maps['user_verified_category_id'] = $verifyid;
		$maps['verified'] = 1;
		$data = D('user_verified')->where($maps)->field('uid, info AS verify_info')->findPage($limit);
		$data['data'] = $this->getUserInfos ( getSubByKey( $data['data'] , 'uid' ) , $data['data'],'basic');
		return $this->addStatus($data['data'] ? $data : []);
	}

	// 按官方推荐分类搜索用户
	public function search_by_uesr_category($value='')
	{
		$limit = 20;
		$this->data['limit'] && $limit = intval( $this->data['limit'] );
		$cateid = intval ( $this->data['cateid'] );
		if ( !$cateid && $this->data['catename']){
			$amap['title'] = t( $this->data['catename'] );
			$cateid = D('user_official_category')->where($amap)->getField('user_official_category_id');
		}
		if ( !$cateid ){
			return $this->addStatus([]);
		}
	 	$maps['user_official_category_id'] = $cateid;
		$data = D('user_official')->where($maps)->field('uid, info AS verify_info')->findPage($limit);
		$data['data'] = $this->getUserInfos ( getSubByKey( $data['data'] , 'uid' ) , $data['data'],'basic');
		return $this->addStatus($data['data'] ? $data : []);
	} 

	public function get_user_category()
	{
		$type = t ( $this->data['type'] );
		switch ($type) {
			//地区分类 最多只列出二级
			case 'area':
				$category = model('Area')->ApigetNetworkList();
				break;

			//认证分类 最多只列出二级
			case 'verify_category':
				$category = model('UserGroup')->where('is_authenticate=1')->findAll();
				foreach($category as $k=>$v){
					$category[$k]['child'] = D('user_verified_category')->where('pid='.$v['user_group_id'])->findAll();
				}
				break;

			//推荐分类 最多只列出二级
			case 'user_category':
				$category = model('CategoryTree')->setTable('user_official_category')->getNetworkList();
				break;

			//标签 tag 最多只列出二级
			default:
				$category = model('UserCategory')->getNetworkListAPI();
				break;
		}
		
		return $this->addStatus($category);
	}
	/**
	 * 粉丝最多
	 * @return Ambigous <number, 返回新的一维数组, boolean, multitype:Ambigous <array, string> >
	 */
	public function get_user_follower(){
		$limit = 20;
		$this->data['limit'] && $limit = intval( $this->data['limit'] );
		$page = $this->data['page'] ? intval($this->data['page']) : 1;
		$limit = ($page - 1) * $limit.', '.$limit;
		
		$followermap['key'] = 'follower_count';
		$followeruids = model('UserData')->where($followermap)->field('uid')->order('`value`+0 desc,uid')->limit($limit)->findAll();
		$followeruids = $this->getUserInfos ( getSubByKey( $followeruids , 'uid' ) , $followeruids,'basic');
		return $followeruids ? $followeruids : [];
	}

	// 按地理位置搜索邻居
	public function neighbors(){
		//经度latitude 
		//纬度longitude
		//距离distance
		$latitude = floatval ( $this->data['latitude'] );
		$longitude = floatval( $this->data['longitude'] );
		//根据经度、纬度查询周边用户 1度是 111 公里
		//根据ts_mobile_user 表查找，经度和纬度在一个范围内。  
		//latitude < ($latitude + 1) AND latitude > ($latitude - 1)
		//longitude < ($longitude + 1) AND longitude > ($longitude - 1)
		$limit = 20;
		$this->data['limit'] && $limit = intval( $this->data['limit'] );
		$map['last_latitude'] = array( 'between' , ($latitude - 1).','.($latitude + 1) );
		$map['last_longitude'] = array( 'between' , ($longitude - 1).','.($longitude + 1) );
		
		$data = D('mobile_user')->where($map)->field('uid')->findpage($limit);
		$data['data'] = $this->getUserInfos ( getSubByKey( $data['data'] , 'uid' ) , $data['data'],'basic');
		return $data['data'] ? $data : [];
	}

	// 记录用户的最后活动位置
	public function checkin(){
		$latitude = floatval ( $this->data['latitude'] );
		$longitude = floatval ( $this->data['longitude'] );
		//记录用户的UID、经度、纬度、checkin_time、checkin_count
		//如果没有记录则写入，如果有记录则更新传过来的字段包括：sex\nickname\infomation（用于对周边人进行搜索）
		$checkin_count = D('mobile_user')->where('uid='.$this->user_id)->getField('checkin_count');
		$data['last_latitude'] = $latitude;
		$data['last_longitude'] = $longitude;
		$data['last_checkin'] = time();
		
		if ( $checkin_count ){
			$data['checkin_count'] = $checkin_count + 1;
			$res = D('mobile_user')->where('uid='.$this->user_id)->save($data);
		} else {
			
			$user = model('User')->where('uid='.$this->user_id)->field('uname,intro,sex')->find();
			$data['nickname'] = $user['uname'];
			$data['infomation'] = $user['intro'];
			$data['sex'] = $user['sex'];
			
			$data['checkin_count'] = 1;
			$data['uid'] = $this->user_id;
			$res = D('mobile_user')->add($data);
		}
		return $res ? 1 : 0;
	}
	
	
	public function isValidEmail($email) {
		return preg_match("/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/i", $email) !== 0;
	}
	
	function authorize()
	{
		$login = $_GET['uid'];
		$password = $_GET['passwd'];
		$error = null;
		$data = null;

		if(empty($login) || empty($password)) {
			$error['status'] = 0;
			$error['info'] = L('PUBLIC_ACCOUNT_EMPTY');			// 帐号或密码不能为空
			return $error;
		}

		if($this->isValidEmail($login)){
			$map = "(login = '{$login}' or email='{$login}') AND is_del=0";
		}else{
			$map = "(login = '{$login}' or uname='{$login}') AND is_del=0";
		}
		
		if(!$user = model('User')->where($map)->find()) {
			$error['status'] = 0;
			$error['info'] = L('PUBLIC_ACCOUNT_NOEXIST');			// 帐号不存在
			return $error;
		}

		$uid  = $user['uid'];
		// 记录登陆日志，首次登陆判断
		$this->rel = D('LoginRecord')->where("uid = ".$uid)->field('locktime')->find();

		$login_error_time = cookie('login_error_time');

		if($this->rel['locktime'] > time()) {
			$error['status'] = 0;
			$error['info'] = L('PUBLIC_ACCOUNT_LOCKED');			// 您的帐号已经被锁定，请稍后再登录
			return $error;
		}
		
		if($password && md5(md5($password).$user['login_salt']) != $user['password']) {
			$login_error_time = intval($login_error_time) + 1;
			cookie('login_error_time', $login_error_time);
			
			$error['status'] = 0;
			$error['info'] = '密码输入错误，您还可以输入'.(6 - $login_error_time).'次';			// 密码错误

			if($login_error_time >=6) {
				// 记录锁定账号时间
				$save['locktime'] = time() + 60 * 60;
				$save['ip'] = get_client_ip();
				$save['ctime'] = time();
				$m['uid'] = $save['uid'] = $uid;

				$error['info'] = L('PUBLIC_ACCOUNT_LOCK');		// 您输入的密码错误次数过多，帐号将被锁定1小时
				// 发送锁定通知
				model('Notify')->sendNotify($uid, 'user_lock');

				cookie('login_error_time', null);

				if(empty($this->rel)) {
					D('')->table(C('DB_PREFIX').'login_record')->add($save);
				} else {
					D('')->table(C('DB_PREFIX').'login_record')->where($m)->save($save);
				}
			}
			$error['status'] = 0;
			return $error;
		} else {
			$logData['uid'] = $uid;
			$logData['ip'] = get_client_ip();
			$logData['ctime'] = time();
			D('')->table(C('DB_PREFIX').'login_logs')->add($logData);
			$user['status'] = 1;
			return $user;
		}
	}
	
	function register(){

		$invite = t($_GET['invate']);
		$inviteCode = t($_GET['invate_key']);
		$email = t($_GET['email']);
		$uname = t($_GET['uname']);
		$sex = 1 == $_GET['sex'] ? 1 : 2;
		$password = trim($_GET['password']);
		$repassword = trim($_GET['repassword']);
		
		$_register_model = model('Register');
		$_user_model = model('User');
		
		$data = null;
		
		//检查验证码
		if (md5(strtoupper($_GET['verify'])) != $_SESSION['verify']) {
			$data['status'] = 0;
			$data['info'] = '验证码错误';
			return $data;
		}
		
		if(!$_register_model->isValidName($uname)) {
			$data['status'] = 0;
			$data['info'] = '用户名:'.$_register_model->getLastError();
			return $data;
		}
		
		if(!$_register_model->isValidEmail($email)) {
			$data['status'] = 0;
			$data['info'] = '邮箱:'.$_register_model->getLastError();
			return $data;
		}
		
		if(!$_register_model->isValidPassword($password, $repassword)){
			$data['status'] = 0;
			$data['info'] = '密码:'.$_register_model->getLastError();
			return $data;
		}
		
		// if (!$_POST['accept_service']) {
		// 	$this->error(L('PUBLIC_ACCEPT_SERVICE_TERMS'));
		// }
		
		$login_salt = rand(11111, 99999);
		$map['uname'] = $uname;
		$map['sex'] = $sex;
		$map['login_salt'] = $login_salt;
		$map['password'] = md5(md5($password).$login_salt);
		$map['login'] = $map['email'] = $email;
		$map['reg_ip'] = get_client_ip();
		$map['ctime'] = time();
		
		// 添加地区信息
		$map['location'] = t($_GET['city_names']);
		$cityIds = t($_GET['city_ids']);
		$cityIds = explode(',', $cityIds);
		isset($cityIds[0]) && $map['province'] = intval($cityIds[0]);
		isset($cityIds[1]) && $map['city'] = intval($cityIds[1]);
		isset($cityIds[2]) && $map['area'] = intval($cityIds[2]);
		// 审核状态： 0-需要审核；1-通过审核
		$map['is_audit'] = $this->_config['register_audit'] ? 0 : 1;
		// 需求添加 - 若后台没有填写邮件配置，将直接过滤掉激活操作
		$isActive = $this->_config['need_active'] ? 0 : 1;
		if ($isActive == 0) {
			$emailConf = model('Xdata')->get('admin_Config:email');
			if (empty($emailConf['email_host']) || empty($emailConf['email_account']) || empty($emailConf['email_password'])) {
				$isActive = 1;
			}
		}
		$map['is_active'] = $isActive;
		$map['first_letter'] = getFirstLetter($uname);
		//如果包含中文将中文翻译成拼音
		if ( preg_match('/[\x7f-\xff]+/', $map['uname'] ) ){
			//昵称和呢称拼音保存到搜索字段
			$map['search_key'] = $map['uname'].' '.model('PinYin')->Pinyin( $map['uname'] );
		} else {
			$map['search_key'] = $map['uname'];
		}
		$uid = $_user_model->add($map);
		if($uid) {
			// 添加积分
			model('Credit')->setUserCredit($uid,'init_default');
			// 如果是邀请注册，则邀请码失效
			if($invite) {
				$receiverInfo = model('User')->getUserInfo($uid);
				// 验证码使用
				model('Invite')->setInviteCodeUsed($inviteCode, $receiverInfo);
				// 添加用户邀请码字段
				model('User')->where('uid='.$uid)->setField('invite_code', $inviteCode);
				//给邀请人奖励
			}
		
			// 添加至默认的用户组
			$userGroup = model('Xdata')->get('admin_Config:register');
			$userGroup = empty($userGroup['default_user_group']) ? C('DEFAULT_GROUP_ID') : $userGroup['default_user_group'];
			model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
		
			//注册来源-第三方帐号绑定
			if(isset($_GET['other_type'])){
				$other['type'] = t($_GET['other_type']);
				$other['type_uid'] = t($_GET['other_uid']);
				$other['oauth_token'] = t($_GET['oauth_token']);
				$other['oauth_token_secret'] = t($_GET['oauth_token_secret']);
				$other['uid'] = $uid;
				D('login')->add($other);
			}

			//判断是否需要审核
			if($this->_config['register_audit']) {
				$this->redirect('public/Register/waitForAudit', array('uid' => $uid));
			} else {
				if(!$isActive){
					$_register_model->sendActivationEmail($uid);
					$this->redirect('public/Register/waitForActivation', array('uid' => $uid));
				}else{
					D('Passport')->loginLocal($email,$password);
					//$this->assign('jumpUrl', U('public/Passport/login'));
					$data['status'] = 1;
					$data['info'] = '恭喜您，注册成功';
				}
			}

		} else {
			$data['info'] = L('PUBLIC_REGISTER_FAIL');			// 注册失败
		}
		return $data;
	}
	
	/*
	 * 得到分组列表
	 */
	function get_follow_group()
	{
		return $this->addStatus(model('FollowGroup')->_getGroupList($this->data['uid']));
	}
	
	/*
	 * 得到指定用户关注的某个用户的所在的组
	 */
	function get_follow_group_info()
	{
		return $this->addStatus(model('FollowGroup')->getGroupStatus($this->data['uid'],$this->data['fid']));
	}
	
	/*
	 * 移动好友至分组
	*/
	function move_friend()
	{
		return $this->addStatus(model('FollowGroup')->_setFollowGroup($this->data['uid'],$this->data['fid'],$this->data['gid'], $this->data['action']));
	}
	/*
	 * 根据分组得到好友ID
	 */
	function get_users_by_group()
	{
		return $this->addStatus(model('FollowGroup')->getUsersByGroup($this->data['uid'],$this->data['gid']));
	}
	
	/*
	 * 根据分组得到好友ID - 分页
	*/
	function get_users_by_group_page()
	{
		return $this->addStatus(model('FollowGroup')->getUsersByGroupPage($this->data['uid'],$this->data['gid']));
	}
	
	/*
	 * 得到所有未分组好友ID
	*/
	function get_users_default_group()
	{
		return $this->addStatus(model('FollowGroup')->getDefaultGroupByAll($this->data['uid']));
	}
	
	/*
	 * 得到所有未分组好友ID - 分页
	*/
	function get_users_default_group_page()
	{
		return $this->addStatus(model('FollowGroup')->getDefaultGroupByPage($this->data['uid']));
	}
	
	/**	
	 * 修改制定用户的分组名称
	 *
	 */
	function set_group()
	{
		return $this->addStatus(model('FollowGroup')->_saveGroup($this->data['uid'],$this->data['title'],$this->data['gid']));
	}
	
	/*
	 * 创建一个分组
	 */
	function create_group()
	{
		return $this->addStatus(model('FollowGroup')->setGroup($this->data['uid'],$this->data['title']));
	}
	
	/*
	 * 删除一个分组
	*/
	function delete_group()
	{
		return $this->addStatus(model('FollowGroup')->deleteGroup($this->data['uid'],$this->data['gid']));
	}
}